import {queryOutFtpList,} from '@/services/workspace';

export default {
  namespace: 'ftpModel',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },
    //目录树结构
    dirTreeList: [],

  },

  effects: {
    * queryOutFtpList({payload}, {call, put}) {
      const response = yield call(queryOutFtpList, payload);
      if (response && response.result == 'ok') {
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },

    //查询目录组织树
    * queryDirTreeList({payload, callback}, {call, put}) {
      const response = yield call(queryDirTreeList, payload);
      if (response && response.result == 'ok') {

        yield put({
          type: 'saveDirTreeList',
          payload: response,
        });
      }
    },
    //移动文件
    * moveFile({payload, callback}, {call, put}) {
      const response = yield call(moveOutFileToPrivate, payload);
      if (callback) callback(response);
    },
    * getPreviewLinkPath({payload, callback}, {call, put}) {
      const response = yield call(getPreviewLinkPath, payload);
      if (callback) callback(response);
    },

  },

  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload.data,
      };
    },
  },
};
